home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group95b.txt
/
000011_icon-group-sender _Thu Feb 9 10:46:19 1995.msg
< prev
next >
Wrap
Internet Message Format
|
1995-09-18
|
2KB
Received: by cheltenham.cs.arizona.edu; Thu, 9 Feb 1995 09:46:28 MST
From: cargo@ironwood.cray.com (David Cargo)
Message-Id: <9502091646.AA02575@fir121>
Date: Thu, 9 Feb 1995 10:46:19 -0600
To: icon-group@cs.arizona.edu
Subject: string invocation example
X-Mailer: [XMailTool v3.1.0]
Content-Length: 1658
Errors-To: icon-group-errors@cs.arizona.edu
The February Icon Analyst has a cover article about string invocation.
I wrote this program to take advantage of string invocation for
filtering text files in a flexible fashion.
############################################################################
#
# File: filter.icn
#
# Subject: Program to apply Icon functions to lines of input
#
# Author: David S. Cargo
#
# Date: February 9, 1995
#
############################################################################
#
# Version: 1.1
#
############################################################################
#
# This program uses string invocation to apply an Icon function to lines
# of input to produce lines of output.
#
#
############################################################################
#
# Links: none
#
# Requires: string invocation
#
############################################################################
procedure main(args)
local arglist, function_name, line
(*args > 0) | Usage()
function_name := get(args)
(function_name == function()) | possible_match(function_name)
if *args = 0
then while line := read() do write(function_name(line))
else
{
arglist := [] ||| args
while arglist[1] := read() do write(function_name!arglist)
}
return
end
procedure Usage()
every write(function())
stop("Usage: filter functionname [arg1 [arg2 ...]] <stdin >stdout")
end
procedure possible_match(function_name)
local fname
write(image(function_name), " is not the name of any function.")
every fname := function() do
if find(function_name, fname)
then write(fname)
stop()
end